package com.mera.tektronix.csviewer.transformers;

import java.util.LinkedList;
import java.util.List;

public abstract class AbstractTransformer<DTO, DOMAIN> implements ITransformer<DTO, DOMAIN> {

	protected abstract DOMAIN getDomainInstance(DTO dto);
	protected abstract DTO getDtoInstance(DOMAIN domain);
	protected abstract void transformDtoToDomainInternal(DTO dto, DOMAIN domain);
	protected abstract void transformDomainToDtoInternal(DOMAIN domain, DTO dto);
	
	@Override
	public DOMAIN transformDtoToDomain(DTO dto) {
		DOMAIN domain = getDomainInstance(dto);
		transformDtoToDomainInternal(dto, domain);
		return domain;
	}

	@Override
	public DTO transformDomainToDto(DOMAIN domain) {
		DTO dto = getDtoInstance(domain);
		transformDomainToDtoInternal(domain, dto);
		return dto;
	}
	
	@Override
	public List<DOMAIN> transformDtoToDomainList(List<DTO> listDto) {
		List<DOMAIN> domainList = new LinkedList<DOMAIN>();
		
		for(DTO dto : listDto) {
			DOMAIN domain = transformDtoToDomain(dto);
			domainList.add(domain);
		}
		
		return domainList;
	}
	
	@Override
	public List<DTO> transformDomainToDtoList(List<DOMAIN> listDomain) {
		List<DTO> dtoList = new LinkedList<DTO>();
		
		for(DOMAIN domain : listDomain) {
			DTO dto = transformDomainToDto(domain);
			dtoList.add(dto);
		}
		
		return dtoList;
	}
	
}
